package com.lmonkey.servlet.my;

import com.lmonkey.servic.USERDao;
import com.lmonkey.shop.USER;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/shangc/doaddressupdate")
public class DoAddressUpdate extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        //获取参数
        String name = request.getParameter("name");
        String name1 = request.getParameter("name1");
        String id = request.getParameter("userid");
        String userp = request.getParameter("userp");
        String useraddress = request.getParameter("useraddress");

        //进行查找地址
        int co = 0;
        co = USERDao.select1ById(id,name1);
        System.out.println(co+"5"+id+name1);
        int fl = 0;
        if (co>0){
            fl = 1;
        }

        //进行修改
        int count = 0;
        count = USERDao.updateAddress(name,id,userp,useraddress,fl,name1);

        String eids = request.getParameter("eids");
        if (eids != null){
            if (count>0){
                response.sendRedirect("orderselect?eids="+eids);
            }else {
                PrintWriter out = response.getWriter();
                out.println("<script>alert('修改失败');location.href='orderselect?eids="+eids+"';</script>");
            }
        }else{
            if (count>0){
                response.sendRedirect("addressselect");
            }else {
                PrintWriter out = response.getWriter();
                out.println("<script>alert('修改失败');location.href='addressselect';</script>");
            }
        }

    }
}
